﻿@model List<DauGiaApp.Models.DauGia>
@{
    
    ViewBag.Title = "San pham dau gia";
}
<link href="../../Content/datdaugia.css" rel="stylesheet" type="text/css" />
<link href="../../Content/jquery.countdown.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery-1.6.js" type="text/javascript"></script>
<script src="../../Scripts/countdown/jquery.countdown.js" type="text/javascript"></script>
<script src="../../Scripts/D4Scripts/d4script.js" type="text/javascript"></script>
<script src="../../Scripts/timer.js" type="text/javascript"></script>
@{
    
    if (Model.Count == 0)
    {
    <h2 class="title_hot">
        Không có sản phẩm nào đang được đấu giá</h2>
    }
    else
    {
    <h2 class="title_hot">
        Các sản phẩm đang được đấu giá</h2>
    }
}
@foreach (var dg in Model)
{
    DauGiaApp.Models.SanPham item = dg.LaySanPham();
    <div class="item_sanpham_dg" MaDauGia="@dg.MaDauGia">
        <h1 class="item_tensp_dg">
            <a href="/DauGia/ChiTiet?id=@item.MaSanPham">@item.TenSanPham</a></h1>
        <div class="khunganh_dg">
            <img class="anhdaihien_dg" src="../../Content/images/@item.LayAnhDaiDien()" alt="anh" />
        </div>
        <table>
            <tr class="gia_dght">
                <td>
                    Giá hiện tại
                </td>                                
                <td class="giahientai-value" >@dg.GiaKhopLenh VNĐ
                </td>
            </tr>
            <tr class="nguoi_dght">
                <td>
                    Người Bid
                </td>                                
                <td class="nguoihientai-value" >@dg.LayTKDGCuoi().TenTaiKhoan VNĐ
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <div class="countdown" MaDauGia="@dg.MaDauGia"  >@dg.ThoiGianKetThuc</div>
                </td>
            </tr>
            
            <tr>
                <td>
                    Giá khởi điểm
                </td>
                <td>@item.GiaKhoiDiem VNĐ
                </td>
            </tr>
        </table>
        <form onsubmit="return false;" class="frm-bid" MaDauGia="@dg.MaDauGia">
        <input type="hidden" name="MaDauGia" value="@dg.MaDauGia"/>
        Giá Bid
        <input type="text" name="GiaTien" />
        <button  class="btn_datgia" MaDauGia="@dg.MaDauGia">
            @*<img src="../../Content/images/bid_btn.jpg" alt="dat gia" />*@
        </button>
        </form>
    </div>
    
}
<script type="text/javascript">
    
    function DatGia(madg) {
        var $form = $("form.frm-bid[MaDauGia='" + madg + "']");
        $.ajax({
            type: "POST",
            url: "/DauGia/DatGia",
            data: $form.serialize(),
            dataType: "text json",
            success: function (data) {
                if (data.KetQua == 'ThanhCong') {
                    UpdateCountDown();
                } else {
                    if (data.ThongBao == 'DangNhap') {
                        window.location.replace("/TaiKhoan/DangNhap");
                    } else {
                        alert(data.ThongBao);
                        UpdateCountDown();
                    }
                }

            }
        });
    }

////    function CapNhatBid(madg) {
////        var $form = $("form.frm-bid[MaDauGia='" + madg + "']");
////        var stringReq = "MaDauGia=" + madg;
////        $.ajax({
////            type: "POST",
////            url: "/DauGia/CapNhatBid",
////            data: stringReq,
////            dataType: "text json",
////            success: function (data) {
////                eleString = ".item_sanpham_dg[MaDauGia='" + madg + "'] table tr.gia_dght td.giahientai-value"
////                $(eleString).text(data.GiaKhopLenh);
////                $(eleString).hide('fast');
////                $(eleString).fadeIn('slow');
////            }
////        });
////    }
    $(document).ready(function () {
        GetCountDown();
        $("form.frm-bid button.btn_datgia").click(function () {
            madg = $(this).attr('MaDauGia');
            DatGia(madg);
        });

        $.timer(4000, function (timer) {
            UpdateCountDown();
        });
        
    });
    

</script>
